package model;

public class Student {
    //成员属性:学号/姓名/性别/年龄
    private String stuNo;
    private String stuName;
    private String stuSex;
    private int stuAge;


    public String getStuNo() {
        return stuNo;
    }

    public void setStuNo(String stuNo) {
        this.stuNo = stuNo;
    }

    public String getStuName(){
        return stuName;
    }

    public void setStuName(String stuName){
        this.stuName=stuName;
    }

    public String getStuSex() {
        return stuSex;
    }

    public void setStuSex(String stuSex) {
        if (stuSex.equals("男")||stuSex.equals("女")){
            this.stuSex = stuSex;
        }else {
            this.stuSex="男";
        }
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        if (stuAge<10||stuAge>100){
            this.stuAge=18;
        }
        this.stuAge = stuAge;
    }

    //无参构造
    public Student() {
    }
    //多参构造,实现对全部属性的赋值
    public Student(String stuNo, String stuName, String stuSex, int stuAge) {
        this.setStuNo(stuNo);
        this.setStuName(stuName);
        this.setStuSex(stuSex);
        this.setStuAge(stuAge);
    }
    //学生与专业关联方案1:特点:简单
    public String introduction(String subName,int subLife){
        String str="学生信息如下:\n姓名:"+this.getStuName()+"\n学号:"+this.getStuNo()+"\n性别:"+this.getStuSex()+"\n年龄:"+this.getStuAge()+"岁"+"\n专业名称:"+subName+"\n学制年限:"+subLife;
        return str;
    }
    //学生与专业关联方案2:更方便
    public String instruction(Subject mySubject){
        String str="学生信息如下:\n姓名:"+this.getStuName()+"\n学号:"+this.getStuNo()+"\n性别:"+this.getStuSex()+"\n年龄:"+this.getStuAge()+"岁"+"\n专业名称:"+mySubject.getSubName()+"\n学制年限:"+mySubject.getSubLife();
        return str;
    }
    //学生与专业关联方案3:关联性强
    private Subject stuSubject;

    public Subject getStuSubject() {
        return stuSubject;
    }

    public void setStuSubject(Subject stuSubject) {
        if (stuSubject==null){
            //体现了无参构造的好处
            this.stuSubject=new Subject();
        }
        this.stuSubject = stuSubject;
    }
    //多参构造,实现对全部属性的赋值
    public Student(String stuNo, String stuName, String stuSex, int stuAge,Subject stuSubject) {
        this.setStuNo(stuNo);
        this.setStuName(stuName);
        this.setStuSex(stuSex);
        this.setStuAge(stuAge);
        this.setStuSubject(stuSubject);
    }
    public String introduction(){
        String str="学生信息如下:\n姓名:"+this.getStuName()+"\n学号:"+this.getStuNo()+"\n性别:"+this.getStuSex()+"\n年龄:"+this.getStuAge()+"岁"+"\n专业名称:"+this.getStuSubject().getSubName()+"\n学制年限:"+this.getStuSubject().getSubLife();
        return str;
    }

}
